﻿<?php
//电商ID
defined('EBusinessID') or define('EBusinessID', '1372094');
//电商加密私钥，快递鸟提供，注意保管，不要泄漏
defined('AppKey') or define('AppKey', '8b8450d7-0c70-4349-8f1d-7ef3a30f4995');
//请求url
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');

//调用查询物流轨迹
//---------------------------------------------
parse_str($_SERVER['QUERY_STRING'], $param);
// var_dump($param);
$logisticResult=getOrderTracesByJson();
$json = (json_decode($logisticResult));
$traces = $json->Traces;
$traces = array_reverse($traces);
// $arr = explode('&&',$_SERVER);

// 运单号
// defined('LogisticCode') or define('LogisticCode', explode("=",$arr[0])[1]);
// // 公司编码
// defined('ShipperCode') or define('ShipperCode', explode("=",$arr[0])[1]);
// $requestData = "{'OrderCode':'','ShipperCode':".ShipperCode.",'LogisticCode':".LogisticCode."}";

// $logisticCode = explode("=",$arr[0])[1];
// $ShipperName = urldecode(explode("=",$arr[1])[1]);
// $ShipperCode = explode("=",$arr[2])[1];

//---------------------------------------------
 
/**
 * Json方式 查询订单物流轨迹
 */
function getOrderTracesByJson(){
    // global $param;
    $logisticCode = str_replace('/','',$_SERVER['PATH_INFO']);
    // $requestData= "{'OrderCode':'76035995989','ShipperCode':'JD','LogisticCode':'76035995989' }";
    // $requestData= "{'OrderCode':'','ShipperCode':'STO','LogisticCode':'3371572510665'}";
    // $requestData= "{'OrderCode':'','ShipperCode':'YD','LogisticCode':'3956662075939'}";
    // $requestData= "{'OrderCode':'','ShipperCode':'ZTO','LogisticCode':'633666349478'}";
    $requestData= "{'OrderCode':'','ShipperCode':'JD','LogisticCode':'".$logisticCode."'}";
    // $requestData = "{'OrderCode':'','ShipperCode':'".$param['ShipperCode']."','LogisticCode':'".$param['logisticCode']."'}";
	$datas = array(
        'EBusinessID' => EBusinessID,
        'RequestType' => '1002',
        'RequestData' => urlencode($requestData) ,
        'DataType' => '2',
    );
    $datas['DataSign'] = encrypt($requestData, AppKey);

	$result=sendPost(ReqURL, $datas);	
	
	//根据公司业务处理返回的信息......
	
	return $result;
}
 
/**
 *  post提交数据 
 * @param  string $url 请求Url
 * @param  array $datas 提交的数据 
 * @return url响应返回的html
 */
function sendPost($url, $datas) {
    $temps = array();	
    foreach ($datas as $key => $value) {
        $temps[] = sprintf('%s=%s', $key, $value);		
    }	
    $post_data = implode('&', $temps);
    $url_info = parse_url($url);
	if(empty($url_info['port']))
	{
		$url_info['port']=80;	
	}
    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
    $httpheader.= "Host:" . $url_info['host'] . "\r\n";
    $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
    $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
    $httpheader.= "Connection:close\r\n\r\n";
    $httpheader.= $post_data;
    $fd = fsockopen($url_info['host'], $url_info['port']);
    fwrite($fd, $httpheader);
    $gets = "";
	$headerFlag = true;
	while (!feof($fd)) {
		if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
			break;
		}
	}
    while (!feof($fd)) {
		$gets.= fread($fd, 128);
    }
    fclose($fd);  
    
    return $gets;
}

/**
 * 电商Sign签名生成
 * @param data 内容   
 * @param appkey Appkey
 * @return DataSign签名
 */
function encrypt($data, $appkey) {
    return urlencode(base64_encode(md5($data.$appkey)));
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?php echo $param['status']; ?></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        h2 {
            font-weight: 500;
            font-size: 30px;
            line-height: 42px;
            margin: 25px 0;
            font-family: PingFangSC-Medium;
        }

        .mb2 {
            margin-bottom: 2px;
        }
        
        .mb25 {
            margin-bottom: 25px;
        }
        .pl20 {
            padding-left: 20px;
        }

        .grey {
            color: #5C5C5C;
        }

        .fz {
            font-size: 14px;
        }

        .main ul {
            list-style: none;
        }

        .item {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            color: #BFBFC0;
        }

        .circle {
            /* display: inline-block; */
            position: relative;
            width: 12px;
            height: 12px;
            background-color: rgba(227, 227, 227, 1);
            -webkit-border-radius:50%;
            border-radius: 50%;
            margin-top: 20px;

        }
        .circle::after {
            content: '';
            position: absolute;
            z-index: -2;
            background: rgba(227, 227, 227, 1);
            width: 2px;
            height: 80px;
            top: 50%;
            left: 50%;
            transform: translateX(-50%);
        }
        .item .right {
            flex: 1;
            padding: 10px 10px 10px 0;
            margin-left: 23px;
            border-bottom: 1px solid rgba(227, 227, 227, 1);
        }
        .right .description {
            font-size: 14px;
            margin-bottom: 5px;
        }
        .right .time {
            font-size: 12px;
        }
        .main li:first-child {
            
        }
        /* .main li:first-child .circle {
            position: absolute;
            background: #4387E8;
            width: 20px;
            height: 20px;
        } */
        .main li:first-child .description {
           color: #000;
        }
        .main li:first-child .circle::after {
            /* left: 6px; */
        }
        .main li:first-child .circle::before {
            content: '';
            position: absolute;
            left: 50%;
            background: #4387E8;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 3px solid #9BC4FF;
            transform: translateX(-50%);
        }

        /* .main li:first-child .circle::before {
            content: '';
            position: absolute;
            z-index: -1;
            top: -20%;
            left: -20%;
            background: #9BC4FF;
            width: 28px;
            height: 28px;
            border-radius: 50%
        } */
    </style>
</head>




<body>
    
    <div class="pl20">
        <h2><?php echo $param['status']; ?></h2>
        <p class="grey fz14 mb2">
            运单号：<?php echo $json->LogisticCode; ?>
        </p>
        <p class="grey fz14 mb25">
            信息来源：京东物流
        </p>
        <div class="main">
            <ul>
            
            <?php
foreach ($traces as $value) {
?>
                <li class="item">
                    <span class="circle"></span>
                    <div class="right">
                        <p class="description"><?php echo $value->AcceptStation; ?></p>
                        <p class="time"><?php echo $value->AcceptTime; ?></p>
                    </div>
                </li>
                <?php
}
?>
            </ul>
        </div>
    </div>
</body>
</html>